package Servlet;

import Bean.Flight;
import Service.FlightService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张
 * Date: 2025-03-10
 * Time: 8:55
 */
//查询航班的详细信息
@WebServlet("/FlightParticularsServlet")
public class FlightParticularsServlet extends HttpServlet {
    private FlightService flightService = new FlightService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf8");
        String flightId = req.getParameter("flightId");
        //根据flightId查询指定航班信息
        Flight flight = flightService.selectByFlightId(flightId);
        if (flight == null) {
            req.setAttribute("status", "error");
            req.setAttribute("message", "数据查询失败,正在更新页面数据!!");
            req.setAttribute("redirectUrl", "RegisterListServlet?pageNo=1");
            req.setAttribute("waitSeconds", 2);
            req.getRequestDispatcher("skip.jsp").forward(req,resp);
        }
        req.setAttribute("flight",flight);
        req.getRequestDispatcher("flight_Particulars.jsp").forward(req,resp);
    }
}
